//
//  MyDataTableViewController.m
//  1243
//
//  Created by 袖手旁觀 on 16/4/7.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "MyDataTableViewController.h"
#import "MyDataTableViewCell.h"
#import "NetWorkTools.h"

@interface MyDataTableViewController ()<UIAlertViewDelegate>

@property (nonatomic,strong)NSDictionary *params;

@end

@implementation MyDataTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    [self.tableView
//     registerNib:[UINib nibWithNibName:@"MyDataTableViewCell" bundle:nil] forCellReuseIdentifier:@"XingYingYangChangJian"];
 
    self.tableView.rowHeight = 200;
    
    [self loadUserData];
    
    self.tableView.tableFooterView = [[UIView alloc] init];
    self.tableView.separatorStyle  = UITableViewCellSeparatorStyleNone;
    
    self.title = @"我的信息";
}

- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section {
    view.tintColor = [UIColor clearColor];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    
    if (self.params.count) {
        MyDataTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"xingYingYangChangJian" ];
        
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"MyDataTableViewCell" owner:nil options:nil] lastObject];
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        NSString *strUrl = [self.params[@"Birthday"] stringByReplacingOccurrencesOfString:@"T" withString:@" "];
        cell.nameLabel.text = [NSString stringWithFormat:@"姓名:%@", self.params[@"RealName"]];
        cell.titleLabel.text = [NSString stringWithFormat:@"开户行:%@", self.params[@"WW"]];
          cell.timeLabel.text =   [NSString stringWithFormat:@"创建时间:%@", [self.params[@"CreateTime"] stringByReplacingOccurrencesOfString:@"T" withString:@" "]];
          cell.email.text =    [NSString stringWithFormat:@"eMail:%@", self.params[@"Email"]];
          cell.phone.text =[NSString stringWithFormat:@"电话:%@", self.params[@"Mobile"]];
        cell.birthDay.text =[NSString stringWithFormat:@"生日:%@", strUrl];
        return cell;
    } else {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        
        if (cell == nil) {
            cell = [[UITableViewCell alloc] init];
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        return cell;
        
    }

    
}

- (void)loadUserData {
    NSDictionary *dict = @{
                           @"UserNumber":[ReadLoginData readLoginData][@"Number"]
                           };
    
    [[NetWorkTools sharedNetWorkTools] objectWithURLDict:dict AndMenthodName:@"INFORMATHIONLISTQUEY" completeBlock:^(id object) {
        
        NSLog(@"%@",object);
        
        if ([[object objectForKey:@"Id"] intValue] == 0) {
            [self.tableView reloadData];
        } else {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:[object objectForKey:@"Message"] delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            alert.tag = 10001;
            [alert show];
        }
        
        NSString *string = [object objectForKey:@"BackData"];
        
        self.params = [NetWorkTools dictionaryWithJsonString:string];
        [self.tableView reloadData];
    }];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView.tag == 10001) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

@end
